*** Predict FCC vs other Cargo
* trying to determine which of the AIS designated "Cargo" vessels are FCC
* so that we can get better vessel counts

capture drop train
capture drop train_unique
capture drop FCCprob
capture drop FCCprob_fill
capture drop FCCpred

capture drop length_ais_bin
capture drop width_ais_bin
capture drop speed_bin
capture drop vesseltype_regstr_filled vesseltype_reg_filled

gen train = inlist(aisyear,2009,2015,2016) & vesseltype_ais=="Cargo":vesseltype
egen train_unique = tag(ves_id) if train

egen length_ais_bin= cut(length_ais), at(50(50)400)
egen width_ais_bin= cut(width_ais), at(0(5)40)
egen speed_bin= cut(avg_speed), at(0(5)50)

capture drop othercargo_port_ves_mean othercargo_port_ves
egen othercargo_port_ves_mean = mean(othercargo_port) , by(ves_id)
gen othercargo_port_ves = (othercargo_port_ves_mean>0)

logit FCC i.length_ais_bin othercargo_port_ves if train_unique 
predict FCCprob if train_unique , pr
predict FCCprob_fill , pr
gen FCCpred = (FCCprob_fill>0.5)

*tab FCCpred FCC if train_unique
*tab FCCpred if vesseltype_ais=="Cargo":vesseltype

* filling in missing vessel types
gen vesseltype_regstr_filled = vesseltype_regstr
* tanker if AIS tanker
replace vesseltype_regstr_filled="Tanker" if vesseltype_ais=="Tanker":vesseltype & vesseltype_regstr==""
* container if AIS cargo and predicted FCC
replace vesseltype_regstr_filled="Container" if vesseltype_ais=="Cargo":vesseltype & FCCpred==1 & vesseltype_regstr==""
* other cargo if AIS cargo and not predicted FCC
replace vesseltype_regstr_filled="Other Cargo" if vesseltype_ais=="Cargo":vesseltype & FCCpred~=1 & vesseltype_regstr==""
encode vesseltype_regstr_filled , gen(vesseltype_reg_filled)
